package sg20.task1;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;
import java.util.ArrayList;

public class TaskOneReducer extends Reducer<Text, Text, Text, Text> {
    String countryString;

    @Override
    protected void reduce(Text key, Iterable<Text> values, Reducer<Text, Text, Text, Text>.Context context) throws IOException, InterruptedException {

        ArrayList<String> vals = new ArrayList<>();
        for (Text value : values) {
            vals.add(value.toString());
            if (!Character.isDigit(value.toString().charAt(0))) {//country
                countryString = value.toString();
            }
        }

        for (String val : vals) {
            if (Character.isDigit(val.charAt(0))) {//university
                context.write(new Text(val + countryString), new Text(""));
            }
        }

    }
}
